package com.person.ntv.service.sys.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.person.common.PageParams;
import com.person.exception.ServiceException;
import com.person.ntv.dao.sys.SysRoleMapper;
import com.person.ntv.entity.sys.SysRole;
import com.person.ntv.entity.sys.SysRoleResource;
import com.person.ntv.service.base.impl.BaseServiceImpl;
import com.person.ntv.service.sys.CommonService;
import com.person.ntv.service.sys.SysRoleResourceService;
import com.person.ntv.service.sys.SysRoleService;
@Service("sysRoleService")
public class SysRoleServiceImpl extends BaseServiceImpl<SysRole> implements SysRoleService{
	@Autowired
   private SysRoleMapper sysRoleMapper;
	@Autowired
   private CommonService commonService;
	@Autowired
   private SysRoleResourceService sysRoleResourceService;
   @Autowired
   public void setBaseMapper(){
	   super.setBaseMapper(this.sysRoleMapper);
   }

@Override
public int deleteByPrimaryKeys(BigDecimal[] ids) {
	try{
		int result=0;
		SysRoleResource srr=new  SysRoleResource();
	    for(BigDecimal id:ids){
	    	result+=deleteByPrimaryKey(id);
	    	//删除关联表
	    	srr.setRoleId(id);
	    	sysRoleResourceService.delete(srr);
	    }
	    return result;
		}catch (Exception e) {
	          e.printStackTrace();
	          throw new ServiceException("系统错误。");
	  }
}

@Override
public Page<SysRole> getRolePage(PageParams params)
		throws ServiceException {
	try{
		PageHelper.startPage(params.getPage(),params.getRows(),params.getOrderStr(null));
		return  sysRoleMapper.selectPage(params.getParams());
		}catch (Exception e) {
	          e.printStackTrace();
	          throw new ServiceException("系统错误。");
	  } 
}

@Override
public int deleteRoleUsers(String roleId) throws ServiceException {
	try{
		return  sysRoleMapper.deleteRoleUsers(roleId);
		}catch (Exception e) {
	          e.printStackTrace();
	          throw new ServiceException("系统错误。");
	  } 
}

@Override
public int addRoleUser(List<Map<String, Object>> list) throws ServiceException {
	try{
		return  sysRoleMapper.addRoleUsers(list);
		}catch (Exception e) {
	          e.printStackTrace();
	          throw new ServiceException("系统错误。");
	  } 
}
   
}
